Store trace context in emit_event, and link it in 'await_event'#64
Store trace context in emit_event, and link it in 'await_event'#64
Conversation
This should result in Sentry displaying a link from the task execution trace (where 'await_event' is called) back to the trace that performed the 'emit_event' call This is stored in a new 'metadata' json column in the events table, which we can use to add additional per-event information in the future (without needing to wrap the user-provided payload)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
|
|
||
| // Check cache for already-received event | ||
| if let Some(cached) = self.checkpoint_cache.get(&checkpoint_name) { | ||
| // No trace linking needed - already done on original receipt |
There was a problem hiding this comment.
Trace linking fails when task wakes from suspension
High Severity
The trace context metadata is never linked when a task resumes after being woken by emit_event. When emit_event wakes a sleeping task, it creates a checkpoint containing only the payload (not the metadata). On resume, TaskContext::create loads this checkpoint into checkpoint_cache. When await_event is called, it hits the cache at line 353 and returns directly, bypassing the SQL query that would fetch metadata from the events table. The trace linking code at lines 392-395 is never reached, breaking the PR's stated goal of linking traces from await_event to emit_event.
This should result in Sentry displaying a link from the task execution trace (where 'await_event' is called) back to the trace that performed the 'emit_event' call
This is stored in a new 'metadata' json column in the events table, which we can use to add additional per-event information in the future (without needing to wrap the user-provided payload)
Note
Adds first-class event metadata for system data (e.g., tracing) and wires it through emit/await paths.
metadata jsonb;ensure_queue_tablescreates it with commentse_*tables, drops/recreatesemit_event(now(queue, name, payload, metadata)) andawait_event(now returns(should_suspend, payload, metadata))await_eventfetches and returnsmetadata; checkpoint returns omit metadata;emit_eventupsertsmetadataalong with payloademit_event_withinjects trace context into eventmetadata(when telemetry enabled);await_event/joinreceivemetadataand link traces;AwaitEventResultupdatedTaskError::EmitEventFailed; tests and queries updated to new function signaturesWritten by Cursor Bugbot for commit 88c631f. This will update automatically on new commits. Configure here.